//需登录的地址
const login_url = [
	
];

import {mapState} from 'vuex'
const mixin = {
	computed:{
		...mapState(['isLogin','userInfo'])
	},
	methods: {
		getUserInfo(){
			var token = uni.getStorageSync('token')
			if(token){
				this.$u.api.getUser().then(res => {
					if(res.code == 1){
						this.$store.commit('LoginSuccess',{
							user:res.data.userInfo,
							token: ''
						})
					}
				})
			}
		},
		//跳转
		Jump(url,type){
			type = type || 'navigateTo'
			console.log(url)
			console.log(type)
			if(url == ''){
				return false;
			}
			if(type == 'navigateTo'){
				uni.navigateTo({
					url:url,
					fail:function(){
						uni.switchTab({
							url:url
						})
					}
				})
			}
			if(type== 'redirectTo'){
				uni.redirectTo({
					url:url
				})
			}
			
		},
		//获取上一页
		getBeforPage(){
			var pages = getCurrentPages();//当前页
			if(pages.length < 2){
				return false;
			}
			return pages[pages.length - 2];//上个页面
		},
		//根据地址获取页面
		getPageByPath(path){
			var pages = getCurrentPages();//当前页
			console.log(pages)
			var paged = false;
			for(var i = 0; i < pages.length;i++){
				if(pages[i].route == path){
					paged = pages[i];
					break; 
				}
			}
			return paged;
		},
		//显示错误信息
		showToastError(msg,callback){
			uni.showToast({
				title: msg,
				icon: 'none',
				success:res => {
					callback && callback();
				}
			})
		},
		//显示错误信息
		showModelError(msg,btn,url,){
			var _this = this;
			uni.showModal({
				content:msg,
				showCancel:false,
				confirmText: btn ? btn : '确定',
				success: function (res) {
						if (res.confirm) {
								if(url != '' && url != undefined){
									_this.Jump(url)
								}
						} else if (res.cancel) {
								console.log('用户点击取消');
						}
				}
			})
		}
		
	}
}
export default mixin
